package com.vchello.service.impl.file;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.vchello.bean.file.File;
import com.vchello.dao.file.FileDao;
import com.vchello.service.file.FileService;

/**
 * 
 * @author power
 *
 */
@Service(value = "fileService")
public class FileServiceImpl extends ServiceImpl<FileDao, File> implements FileService {
	
	@Autowired
	private FileDao fileDao;

	@Override
	public Page<File> findFileByPage(Page<File> page, int fid) {
		Wrapper<File> wrapper = new EntityWrapper<File>();
		wrapper.eq("fid", fid);
		page.setOrderByField("createTime DESC");
		return selectPage(page, wrapper);
	}

	@Override
	public List<File> findFileByFid(int fid) {
		return fileDao.findFileByFid(fid);
	}

	@Override
	public Integer saveFile(File file) {
		return fileDao.insert(file);
	}

	@Override
	public Integer updateFile(File file) {
		return fileDao.updateById(file);
	}

	@Override
	public boolean deleteFile(File file) {
		try {
			fileDao.deleteById(file);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public File findFileById(int id) {
		return fileDao.selectById(id);
	}

	@Override
	public Page<File> findFileByPage(Page<File> page, File file) {
		Wrapper<File> wrapper = new EntityWrapper<File>(file);
		return selectPage(page, wrapper);
	}

}
